home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / util / boot / ShellUpdate.lha / Documentation / Shell < prev    next >
Text File  |  2002-01-19  |  31KB  |  666 lines

  1.         Amiga-OS Shell Documentation
  2.  
  3. Abstract: This document describes the command line syntax and features of 
  4. the Amiga-OS Shell. Specifically, the shell described hereafter is the V45
  5. shell of BB2. Not all issues apply to the V40 release of the shell.
  6.  
  7. ______________________________________________________________________________
  8.  
  9. The purpose of the Amiga-OS shell is to parse its input stream for commands,
  10. then locate these commands either on disk or in memory, and execute these
  11. commands. An input stream is typically the stream of a console handler, as
  12. for example the CON: window or a ViNCEd window. Other input streams are
  13. command files, or "batch files" as they are called sometimes. The most 
  14. popular batch file is of course the "Startup-Sequence" in the S: assign.
  15.  
  16. The input stream is therefore read line by line, that is, up to a terminating
  17. line feed character (or the end of file, where the shell generates this
  18. line feed implicitly). Should the input be read from a console window, this
  19. line feed is of course generated by the console handler as soon as the user
  20. presses the return key.
  21.  
  22. The input line is then scanned for the command itself and for the input/output
  23. and error redirection of the command defining the streams the command will
  24. print to, will read its input from and may write its diagnostic output to.
  25. Furthermore, the shell also handles expansion of back-tick sequences, aliases
  26. and variables. A special feature of the shell is the "&" character and the
  27. "+" sign at the end of a line, further the comment introducer ";". All
  28. this is described in more detail below.
  29.  
  30. Even though the shell parses the command line, it does not prepare argument
  31. lists for the command to be executed; the command line is scanned for
  32. shell specific control features like input/output redirection or back-ticks,
  33. and the remaining input is forwarded as is to the command. It is the matter 
  34. of the command itself to parse this input string a second time. This has the
  35. unfortune side effect that the shell has to second-guess about the expected
  36. syntax of the appropriate command; for the time being, the shell assumes 
  37. the following syntax, which - surprise, surprise - coincides with the syntax
  38. of the ROM function ReadArgs() resp. ReadItem() used by most commands anyhow:
  39.  
  40. This pair of commands knows only two special characters - or maybe four,
  41. depending on how you count: Blanks = the space character and the TAB which 
  42. are considered equivalent, the double quote " and the asterisk * as the BCPL 
  43. style escape character. A command argument is to be understood as a sequence
  44. of non-blank characters up to the line feed, unless the blanks and the 
  45. remaining argument are enclosed in double quotes. Interestingly, this goes 
  46. only for quotes following a blank space. Quotes within an argument, meaning
  47. not following a blank, are not counted as argument separators. Hence,
  48.  
  49. list abc 
  50. list ab"cd"ef
  51. list abcd"
  52.  
  53. present all three the attempt to run "list" with one single argument in
  54. which the quote stands for itself.
  55. Within quoted arguments, and only there(!) the escape character * gets
  56. its special meaning. Outside of quotes, the star stands for itself.
  57.  
  58. Four *-escaped sequences exist: ** is the star itself, *" the double
  59. quote, *N a line feed character and *E an "escape" character, of ASCII
  60. code 27 = hex 0x1B. Therefore,
  61.  
  62. echo "**"
  63. echo **
  64.  
  65. prints one star, and two stars respectively. Unlike other claims, the 
  66. sequence "*E[" is not directly related to the "csi" character of code 
  67. 155 = 0x9b; as far as argument parsing is concerned, this is regarded as 
  68. "escape [". It is merely the console driver which interprets the latter as
  69. a substitute for "csi", neither ReadItem() nor ReadArgs() do.
  70.  
  71. Even though these are all syntax rules as far as the ROM argument parsing 
  72. routines are concerned, the shell itself parses its input line as well, and
  73. performs various operations on this line before it is provided as input to
  74. the command to be executed.
  75.  
  76. The first step is back-tick substitution; then the first argument according
  77. to the above rules is parsed off, ignoring leading blanks. Alias substitution
  78. follows next. As soon as the alias expansion fails to expand further, it
  79. checks whether the command name is a shell variable to be substituted, and
  80. then tries to locate the command to be executed. This may be either an
  81. explicit command found in the current directory, the command search path
  82. or the resident list, or an implicit command for script files, non-executable
  83. files or directories. The last step parses the command arguments for shell
  84. variables to be substituted, and for input/output redirection. All these
  85. steps are described in more detail in the following sections.
  86.  
  87.  
  88. 1) Variable substitution: Local or global variables are set by means of the 
  89. "set" or "setenv" commands. Both are build into the ROM, or the Shell-Segment,
  90. as "resident commands". Should the shell find a variable specification on the
  91. command line, this specification is replaced by the contents of the variable 
  92. before the line is feed into the command as input, or used as the command to
  93. be loaded directly.
  94.  
  95. A variable specification is either a $ sign, followed by alpha-numeric
  96. characters, or a "${" sequence followed by arbitrary characters up to the line
  97. end and a pairing "}" brace to end the variable name. The braces itself do not
  98. count as part of the variable name itself and are therefore discarded. Should
  99. the variable be undefined, no substitution takes place and the $ followed by
  100. the supposed to be variable name stands for itself. An alpha-numeric character
  101. is here any digit, any lower or upper case character or any national character
  102. within the code range of 161..255, i.e. hex 0xa1..0xff. Hence,
  103.  
  104. echo $a
  105. echo ${a}
  106.  
  107. print the same text if there should be a variable named "a", otherwise both
  108. print the argument literally. Even though the above side effect can be used to
  109. test whether a variable has been set or not, the shell offers a more
  110. orthogonal way to check the existence of a variable, namely by $? followed by
  111. the variable to be tested for existence. This expression returns the string 0 
  112. if the variable is not defined, or 1 otherwise. Hence,
  113.  
  114. echo $?a
  115. echo $?{a}
  116.  
  117. generate the same output, 0 for a undefined and 1 for a defined. Note that
  118. the ? is part of the $, and not part of the variable name.
  119.  
  120. The second related sequence is $?? which returns 1 only if the variable is
  121. defined as a global variable, i.e. exists as a file within the ENV: device.
  122.  
  123. The usage of { } allows rather weird variable names, even names containing
  124. spaces, escape characters, question marks, quotes, ">" or "<". Due to a side
  125. effect of the internal working, ":" does NOT work as part of any variable
  126. name; unfortunately this cannot be fixed since variables are stored by a
  127. device handler that reacts in a special way on ":". Similar restrictions arise
  128. for the slash / that implies a special meaning for global variables. 
  129. (Make a guess how!)
  130.  
  131. The $ itself can be escaped by an asterisk, hence *$ stands for a single $.
  132. Unfortunately, THIS meaning of escaping is independent of the * concerning the
  133. argument parsing mentioned above, and is therefore valid within and outside 
  134. of quotes, but only in front of a $ sign (and other shell-only tokens like the
  135. back-tick ` and the bracket [, see below). For the same reason, the parsing of
  136. variable names, though not variable expansion, works the same way within and
  137. outside of quotes, except that stars * that are not in front of $ have a
  138. different meaning. Therefore, confusingly,
  139.  
  140. echo ${*}
  141. echo "${**}"
  142.  
  143. address the same variable, namely *, whereas both
  144.  
  145. echo *$
  146. echo "*$"
  147.  
  148. print the same string $, regardless of the quotes.
  149.  
  150. The escaping can be escaped with another star as well. Hence,
  151.  
  152. echo **$a
  153.  
  154. will print a star, followed by the contents of a. This kind of escaping the
  155. $ sign is independent of the quotation as well and works only in front of $
  156. and related shell-only tokens. Therefore,
  157.  
  158. echo "**$a"
  159.  
  160. does right the same. More precisely, $ stands for itself with an odd number of
  161. stars in front, and is regarded as variable expansion command with an even
  162. number of stars. Since variable substitution happens before argument analysis,
  163.  
  164. echo "***$a"
  165.  
  166. will be parsed as "star, star, escaped dollar, a" on expanding variables, and
  167. the resulting string is analyzed as argument of "echo" as "**$a" with the $
  168. meaning of a literal "$". Now, the star escapes the second star within the
  169. quoted argument: echo prints therefore *$a onto the console. Since * is not an
  170. escape character for itself within arguments,
  171.  
  172. echo ***$a
  173.  
  174. will print one star more instead, but the interpretation of $ does not change.
  175. Clearly, all this is messy, and can be understood only in the historical
  176. context of the Amiga shell where $ was added after argument parsing syntax has
  177. been set in stone. The very same rules for escaping apply to ` and [ as well,
  178. for exactly the same reason.
  179.  
  180. The main idea of the above rules is that $ should not influence argument
  181. parsing "too much", should work outside and inside of quotes, but should be
  182. escapable by the same BCPL syntax. Looking back, a backslash-driven 
  183. and more consistent escaping mechanism would have been more appropriate, of
  184. course.
  185.  
  186.  
  187. A second rule formulates how variable expansion interacts with quoting:
  188. Should the $ sequence be within double quotes, and should the variable
  189. contents be quoted as well, the outermost pair of quotes of the variable
  190. contents gets removed. Otherwise, the result could have been a quote within
  191. a quote, undesirably terminating the argument. The following example 
  192. demonstrates this:
  193.  
  194. set a "*"hi*""        ;defines a as "hi", note the escaping of quotes
  195.             ;due to a first parsing step before executing the
  196.             ;set command.
  197. echo "a is $a"        ;results in "a is hi"
  198.  
  199. Leaving the quotes around $a would have resulted in
  200.  
  201. echo "a is "hi""
  202.  
  203. This would be interpreted as two arguments rather than one, the first one
  204. being "a is " and the second one being hi"". 
  205.  
  206. If this is undesirable, set the local variable "keepdoublequotes" to "on"
  207. by the following command
  208.  
  209. set keepdoublequotes on
  210.  
  211. Thereafter, the above command
  212.  
  213. echo "a is $a"        ;results in "a is *"hi*"" and prints a is "hi"
  214.             
  215.  
  216. will get the quotes escaped properly such that the "echo" command really
  217. prints the text including the quotes of the variable contents.
  218.  
  219. The very same idea of "double quoting" is applied to variable expansion
  220. outside of quotes, except  that the shell now either leaves the possibly
  221. quoted variable contents alone, or adds quoting and escaping to guarantee
  222. that the command reads the quotes as part of its argument. Therefore, the
  223. command
  224.  
  225. echo $a            ;results in "hi" with keepdoublequotes off
  226.             ;results in "*"hi*"" with keepdoublequotes on
  227.  
  228. prints either hi or "hi", depending on whether "keepdoublequotes" is "off" or
  229. "on". In most cases, you might find "off" more attractive as it is backwards
  230. compatible, even though it drops one level of quoting. However, if 
  231. "keepdoublequotes" is set to "on", the shell tries to preserve as much of the
  232. original meaning of the variable, possibly adding escape characters.
  233.  
  234.  
  235.  
  236. 2) Alias substitution: Before the shell is trying to locate a command, it
  237. tries to expand this as an alias. Aliases are command renames with additional
  238. argument relocation, to be defined by the shell-resident "alias" command. On
  239. invocation, the alias is then replaced by the contents of the alias, "shifting
  240. remaining arguments to the right" after inserting a blank. Hence,
  241.  
  242. alias foo echo a
  243. foo b
  244.  
  245. will result in the command "echo a b" and the output "a b". With the aid of
  246. the additional alias token [] one can relocate the remaining arguments to
  247. other places, e.g. in front of additional arguments of the alias contents.
  248. No blank is inserted in this case:
  249.  
  250. alias foo echo [] a
  251. foo b
  252.  
  253. will move the "b" in place of the [] and therefore print "b a", the opposite
  254. of the above. No blank spaces are inserted in front of the [], this should be
  255. done manually if required. 
  256.  
  257. alias foo echo []a
  258. foo b
  259.  
  260. will therefore really print "ba". Unfortunately, the brackets do not try to
  261. analyze the argument syntax for traditional reasons and work therefore only
  262. the first time within the alias contents, i.e.
  263.  
  264. alias foo echo [] a []
  265.  
  266. will not work as expected. The second [] is regarded as literal bracket.
  267. Future releases might introduce further refinements of [] that allow finer
  268. control of the arguments.
  269.  
  270. Similar to the $ sign, the [] can be escaped by a *, applying the very same
  271. messy rules concerning the counting of stars. However, one should now be even
  272. aware that aliases must enter the shell database somehow: This is of course
  273. done by the "alias" command which, by itself, parses its arguments *again*.
  274. Hence, should it be necessary to enclose the "alias body" of the alias command
  275. in double quotes, then all stars MUST BE DOUBLED.
  276.  
  277. alias bracket "echo **[]"
  278. bracket
  279.  
  280. will just print [] on the console. The ** is escaped into a * by the argument
  281. parsing of the alias command, and *[] escapes into [] upon expansion of the
  282. alias.
  283.  
  284. Once again, the same quotation rules as for variable expansion apply: By 
  285. setting "keepdoublequotes" to "on", you may define whether the shell shall
  286. prevent quotes or shall drop one level of quoting. 
  287.  
  288. Alias expansion happens recursively until no alias are found to expanded any
  289. more: If the expansion of an alias happens to be an alias again, then this
  290. alias is expanded, and so on. Since this would imply the possibility of an 
  291. infinite loop of an alias that expands into itself, or into an alias that 
  292. expands into an alias it was expanded from, no alias will be used more than
  293. once within a single command line. Hence, the following alias definition is
  294. legal:
  295.  
  296. alias hi ho
  297. alias ho echo "ho"
  298.  
  299. and defines the "hi" command to output "ho", whereas the following alias 
  300. definition is asking for trouble:
  301.  
  302. alias gnu gnu is not unix
  303.  
  304. This will first expand "gnu" into "gnu is not unix", and will stop then since
  305. the "gnu" alias has been "used up" already. Since the gnu command cannot be
  306. resolved further - unless of course you provide this command as a binary - an
  307. error message will result.
  308.  
  309. Expansion of aliases can be prevented completely by enclosing the command in
  310. quotes. "hi", therefore, will not try to use the above hi-alias, but will try
  311. to find a file named "hi". Otherwise, alias definition take precedence over
  312. ordinary files, i.e. the alias expansion will be applied first when 
  313. applicable, and only if this fails the shell tries to locate an appropriate 
  314. command.
  315.  
  316.  
  317.  
  318. 3) Back-ticks: As the very first step of command line interpretation, the shell
  319. will expand all back-tick sequences on this line. The commands enclosed in
  320. back-ticks will be executed, and the resulting output, after a mild
  321. preprocessing step described below, is inserted instead of the back-tick
  322. sequence. The reader should be aware that the resulting command line might be
  323. very long; even though the shell itself has no problem to process long lines,
  324. some commands may.
  325.  
  326. The back-tick itself is represented by *`, and hence escaped in the very same
  327. way as the $ sign for variable expansion and the [ bracket of the alias
  328. argument placement operator; this goes also for the messy multiple-star
  329. sequences, hence **` is a literal star followed by a back-tick sequence, and
  330. ***` a literal star followed by a literal back-tick, and so on - see the syntax
  331. description of $ for all the side effects one should expect.
  332.  
  333. The command output of the "backtick'd" command is processed before it replaces
  334. the back-tick sequence, though. The shell removes a final terminating line
  335. feed, should it be present, and replaces all other line feeds by blank spaces.
  336. Finally, the shell handles double quotes in the very same way as for $ and []:
  337. If "keepdoublequotes" is "off", quotes resulting from back-tick sequences
  338. within quotes are removed, and no additional quotes are paired around back-tick
  339. expansions resulting in quoted strings. If "keepdoublequotes" is "on",
  340. however, the shell tries to preserve the meaning of the string as close as 
  341. possible and adds escaping stars to preserve quotes within the command output.
  342.  
  343. The body of the backtick'd sequence is considered to be a separate command
  344. line and is therefore parsed separately. Especially, quotes outside a back-tick
  345. sequence can never match any quote within, and do not influence the meaning of
  346. the back-tick sequence as far as escape characters are concerned. Hence, in the
  347. following two command lines
  348.  
  349. echo `echo *.`
  350. echo "`echo *.`"
  351.  
  352. the star stands for itself, even for the second line. It is not considered to
  353. be "within" the surrounding double quotes and is therefore not treated as an
  354. escape character. However, the reader should be aware of the * as an escape
  355. sequence for the back-tick itself, as mentioned in the first paragraph! The two
  356. commands
  357.  
  358. echo `echo *`
  359. echo "`echo *`"
  360.  
  361. will NOT print a single star since the star in front of the second back-tick
  362. escapes this back-tick and hence disables the expansion of the back-tick
  363. sequence at all. One correct way to print a single star by this admittedly
  364. complex method would be 
  365.  
  366. echo `echo **`
  367.  
  368. whereas 
  369.  
  370. echo `echo ***`
  371.  
  372. prints `echo **` with one star less, namely the star that prevented the last
  373. back-tick to be part of a back-tick sequence. This is again the "count the
  374. stars" rule we have been observing for $ and [].
  375.  
  376. Needless to say, back-tick expansion works also within the prompt, and for the
  377. command itself. 
  378.  
  379. `echo type` s:Startup-Sequence
  380.  
  381. is a rather complex and weird way to display the startup sequence on the
  382. console window, and
  383.  
  384. prompt "*`date*` %N.%S> "
  385.  
  386. prints the date in front of the typical CLI number/directory prompt indicator.
  387. The command to be executed within the prompt should be better fast and small,
  388. of course! The reason for the asterisks in front of the back-ticks is left as
  389. a little exercise for the alert reader.
  390.  
  391.  
  392.  
  393. 4) Input/Output/Error redirection: Each command to be executed inherits three
  394. I/O streams by the shell. An input stream user input is read from, an output
  395. channel the command prints output to, and a diagnostic channel error codes
  396. should appear on. Unfortunately, the consistent use of the latter has never
  397. been very popular and is not even supported to full extend by various Os 
  398. functions; the PrintFault() dos.library call, for instance, does NOT print
  399. to the diagnostic output. Nevertheless, all three streams can be redirected
  400. by appropriate shell constructions:
  401.  
  402. An unquoted > followed by a file name defines the output stream, a < plus file
  403. name the input stream and a *> the diagnostic output channel. Should these
  404. sequences be required as part of any argument for the command, they should be
  405. enclosed in double quotes. Should the shell find more than one similar re-
  406. direction on the command line, all additional redirections are regarded as
  407. literal strings. Hence,
  408.  
  409. echo >t:out >NIL:
  410.  
  411. prints the string ">NIL:" into the file "t:out". Further, the shell applies
  412. special rules to the commands "alias", "run" and "pipe" leaving the parsing of
  413. the redirection tokens to the command itself. This has the effect that, for
  414. example, the following alias
  415.  
  416. alias foo echo foo >t:out
  417.  
  418. defines the "foo" command to print the string "foo" into the "t:out" file,
  419. rather than printing the (empty) result of the alias command into that file.
  420. Similar considerations apply to "run" and "alias" as well, of course.
  421.  
  422. Furthermore, should the variable "oldredirect" set to "on", then the shell
  423. will only try to interpret redirection tokens following immediately the 
  424. command name; otherwise, the position of the redirection tokens do not matter.
  425.  
  426. echo "foo" >t:out
  427.  
  428. will either print "foo" to the file "t:out", or will print "foo >t:out" if
  429. "oldredirect" is set to "on". This is a backwards compatibility feature for
  430. pre V37 shell scripts.
  431.  
  432. Needless to say, the file name argument of >, < and *> must be quoted if it
  433. contains spaces, and can be as well a variable specification by means of $,
  434. or a back-tick sequence. Therefore,
  435.  
  436. set t t:out
  437. echo foo >$t
  438.  
  439. and
  440.  
  441. echo foo >`echo t:out`
  442.  
  443. write both "foo" into the file "t:out". Besides these three commands, the
  444. shell also understands the following additional  redirection tokens: 
  445.  
  446. >> appends the output to a file, or creates it should it be not yet existing.
  447.  
  448. <> redirects both input and output into the same file. However, since this
  449. implies that the input stream must be "cloned", the "file" must be either
  450. NIL: or any kind of interactive device, e.g. CON: or RAW:. An ordinary file
  451. cannot be written to and read from at the same time.
  452.  
  453. *>> works much the same way as >> does, but just for the diagnostic output:
  454. It either creates the file, or appends to an existing stream. 
  455.  
  456. *>< redirects the diagnostic output into the same file as > does. 
  457. Unfortunately, this has to be the default anyhow for compatibility reasons
  458. beyond logic, and is explained below in more detail. *<> is NOT equivalent
  459. to *>< and currently a reserved token.
  460.  
  461. Last but not least, the shell also understands a very special input
  462. redirection using the << token. This token takes a string as argument and
  463. scans the shell input - typically a batch file containing the << redirection -
  464. up to the specified string and pastes the result into the stdin of the
  465. command. The following example may enlighten the reader a bit:
  466.  
  467. ask "Enter a number:" numeric to num
  468. echo $num
  469.  
  470. asks the user for a number - to be entered on the input stream of course - 
  471. and then prints this number. The following silly script will define this
  472. number to be 42:
  473.  
  474. ask "Enter a number:" numeric to num <<end
  475. 42
  476. end
  477. echo $num
  478.  
  479. The lines between "<<end" and the "end" token form the input of the "ask"
  480. command. This may seem rather un-useful here, but may become important if
  481. a command expects rather lengthy user input on the command line and the
  482. command shall be run as part of a shell script. Due to the way how << works,
  483. though, this construction fails for commands launched by the "run" command;
  484. instead, usage of the "&" token described below is recommended because it
  485. knows how to deal with this kind of input redirection.
  486.  
  487.  
  488. Finally, some words concerning the diagnostic output redirection:
  489. Unfortunately, this is not widely used, if it is used at all. Instead, 
  490. commands either print error messages into their ordinary output, or into a
  491. file opened as "*", i.e. the console. The first case is of course out of
  492. control of the shell, but the second case is kept care of: Should the
  493. diagnostic output be some kind of interactive stream, say a console handler,
  494. then *> sets the terminal console task of the command as well, and hence
  495. redirects the "*" output into the  console specified by *>. 
  496.  
  497. Unfortunately, it is quite typical to detach commands by means of "<>NIL:"
  498. from the console. Without further care, this would NOT redirect stderr
  499. anymore and would therefore break existing shell scripts. Hence, some
  500. messy compatibility rules for *> redirection have been established:
  501.  
  502. Without *>    The diagnostic error stream goes into the output
  503.         stream, the command console goes into the current
  504.         console. A "run" command would clear the current console
  505.         anyhow, and would hence dispatch the file from the terminal.
  506.  
  507. With *>        Diagnostic output will go into the specified file,
  508.         the command console is the current console unless
  509.         the specified file is interactive or NIL:. In the
  510.         first case, the program console is set to the 
  511.         controlling console of the stream, in the second
  512.         no terminal console is provided.
  513.  
  514. With *><    Diagnostic output will go into the output stream,
  515.         the command console will be set to the console
  516.         controlling the output stream should this be inter-
  517.         active, or will be cleared in case the output goes
  518.         to NIL:
  519.  
  520. Similar rules apply if the command is run in background by means of the "&"
  521. token, except that there is no default command console unless one is provided
  522. by means of *> or *><. This makes it a bit easier to detach commands from the
  523. shell by using "&" and "<>NIL:". 
  524.  
  525.  
  526. 5) The "&" token: Should the shell find a & sign on the command line that is
  527. surrounded by blank spaces and neither quoted, then this sign is removed from
  528. the command line and the command gets detached from the shell very similar to
  529. what "run" would do. 
  530.  
  531. By default, these commands get a new separate console, and a new console owner
  532. should the console driver support this concept (ViNCEd does, the ROM CON: 
  533. handler does not) and hence make use of the "job control feature" of the
  534. console.
  535.  
  536. These commands will keep the console window locked open unless you explicitly
  537. redirect the command input and output to NIL: - this is simply because
  538. commands launched in this way are handled very similar to commands launched
  539. by "run".
  540.  
  541. There is, however, one important difference between "run" and "&": Unlike
  542. "run", the "&" sign does not detach the command to be run from the standard
  543. input. Hence, "ask &" will still ask for input on the console, "run ask" will
  544. not. Furthermore, "run" doesn't mix with << input redirection, "&" does. All
  545. this is because the "&" sign is handled by the shell directly and is much
  546. better integrated into the internal wiring than "run" could.
  547.  
  548.  
  549. 6) The "+" token: Should a command line end on a single + sign, the shell
  550. waits for additional input and concatenates this input with the previous
  551. command input, including the line feed, but excluding the + sign itself.
  552.  
  553. However, this second line is not parsed as a shell command line, but is
  554. rather placed on the command arguments of the command of the previous line.
  555. Since the ROM ReadArgs() and ReadItem() functions only parse up to the first
  556. line feed character, this additional line is typically lost and is only of
  557. interest for special commands like "run" that read their arguments in a
  558. non-standard way.
  559.  
  560.  
  561. 7) The ";" token: If found unquoted on the command line, this token introduces
  562. a comment. All characters following the semicolon, and the semicolon itself
  563. are removed from the command arguments.
  564.  
  565.  
  566. 8) Loading of commands: Besides aliases that have been discussed above, the
  567. shell knows also the following types of commands:
  568.  
  569. The PIPE command, which is used as soon as one of the pipe tokens is found on
  570. the command line, resident (or so-called "build-in", though this nomenclature
  571. is sort of incorrect) commands, implicit commands, commands on the command
  572. search path, and commands within the current directory.
  573.  
  574. Should the shell find that the user defined either the _pchar or the _mchar
  575. local variables, then the command line is scanned for the contents of these
  576. variables. For historical reasons, both variables should contain strings of at
  577. most two characters in size.
  578.  
  579. If these characters are found, then the shell assumes an implicit "PIPE"
  580. command that is prepended to the full command line before further parsing.
  581.  
  582. Resident commands are found on the dos.library "resident command" list and
  583. are program segments similar to those generated by the LoadSeg() command.
  584. Unlike the latter, they do not get a "fresh" copy of their segments each
  585. time but are assumed not to touch their code and data space; hence, not all
  586. commands should be made resident as they are not "pure". Pure commands are
  587. usually in ROM space, or can be placed onto the list of residents by the
  588. "resident" command, which, by itself, is resident. The "resident" command
  589. checks the "p" bit of the command file whether a certain command can be
  590. made resident or not. Since the "p" bit can be set by hand, this is not
  591. much of a safety feature, though. There original "arp" ("Amiga Replacement
  592. Project") commands where the resident feature goes back to had an additional
  593. check concerning the purity of commands.
  594.  
  595. If a command is neither resident nor an alias, the shell tries to find it on
  596. the command path list, which is controlled by the "path" command. If an
  597. executable binary load file is found, this is assumed to be the command;
  598. should the "h" = "hold" bit of this executable be set as well, the command is
  599. made resident as it is loaded. The same care as for the "p" bit should 
  600. apply to the "h" bit as well.
  601.  
  602. If the file in question is not executable, but the "s" bit is set, then the
  603. first two characters of the file are investigated. If they are "/*", hence a
  604. Rexx-comment introducer, a rexx script is assumed and an implicit "RX" command
  605. is prepended to the argument line. If they are "#!" or ";!", the first line
  606. of the script is assumed to be the file name of a script interpreter. This
  607. name must be enclosed in double quotes should it contain blanks. The script
  608. name itself gets then inserted BETWEEN the command interpreter file name, and
  609. its options on this line.
  610.  
  611. Therefore, the following command interpreter specification on the first line
  612. of the file "foo"
  613.  
  614. #! type HEX
  615.  
  616. will run the following text of foo thru the interpreter "type" with the option
  617. "HEX", as if 
  618.  
  619. type foo HEX
  620.  
  621. has been input on the command line. Note that the HEX option is placed behind 
  622. the "script" file name, and not in front of it.
  623.  
  624. If neither a "/*", a "#!" nor a ";!" is found, the script is assumed to be a
  625. shell script and run thru the "Execute" command. Curiously, "Execute" expands
  626. only the arguments and generates a temporary script file, but the actual
  627. command interpretation of this file is left to the shell again by making use
  628. of a not-so-well documented side effect of the shell segment.
  629.  
  630. If the found file is neither a script, nor executable, the shell checks for
  631. the variable "VIEWER". Should it be found, then the shell further checks
  632. whether the file is any known data type by using the datatypes library. If so,
  633. then the contents of this variable is understood as a command that should be
  634. run to display this file. For this, the contents of the VIEWER variable is
  635. placed in front of the command line before further interpretation. Typically,
  636. VIEWER should be set to the MultiView command, of course:
  637.  
  638. Setenv SAVE VIEWER MultiView
  639.  
  640.  
  641. Finally, if the "file" is in fact a directory, the implicit command "CD" is
  642. assumed and inserted in front of the command line.
  643.  
  644.  
  645. The shell can be restricted to search on the current directory only by
  646. enclosing the command within double quotes; this will remove the resident
  647. command list and the command path from the search targets the shell will scan
  648. for commands.
  649.  
  650.  
  651. 9) Miscellaneous: The shell scans segment except INTERNAL commands for the
  652. "magic cookie" 
  653.  
  654. $STACK:
  655.  
  656. Should it be found, then a decimal string terminated by a line feed (!) is
  657. expected. This string is then regarded as a request to enlarge the stack to
  658. at least the specified amount of bytes.
  659.  
  660. Therefore, the following string near the startup code of your program will
  661. guarantee at least 10240 bytes of stack:
  662.  
  663. char stack[]="$STACK:10240\n";
  664.  
  665. Note that the "\n" is necessary and that "STACK" is in capitals.
  666.